<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>v-model</title>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="app">
        <h2>{{msg}}</h2>
        <input type="v-model" v-model="msg">
        <div>
            <p>用户名：<input type="text" v-model="user.name"></p>
            <p>性别：<input type="text" v-model="user.sex"></p>
            <p>联系电话：<input type="text" v-model="user.phone"></p>
            <p>家庭住址：<input type="text" v-model="user.address"></p>
            <button @click="saveUser(user)">保存</button>
        </div>
        <table border="1px" v-if="users.length!=0">
            <tr>
                <th>用户名</th>
                <th>性别：</th>
                <th>联系电话：</th>
                <th>家庭住址：</th>
                <th>操作</th>
            </tr>
            <tr v-for="(user,index) in users" ::key="index">
                <td>{{user.name}}</td>
                <td>{{user.sex}}</td>
                <td>{{user.phone}}</td>
                <td>{{user.address}}</td>
                <td><button @click="del(index)">删除</button></td>
            </tr>
        </table>
    </div>
</body>
</html>
<script>
    new Vue({
        el:'#app',
        data:{
            msg:'hello vue!',
            user:{
                name:'',
                sex:'',
                phone:'',
                address:''
            },
            users:[],
        },
        methods: {
            saveUser(user){
                this.users.push(user);
                this.user={}
            },
            //删除
            del(index){
                this.users.splice(index,1)
            }
        }
    })
</script>